
$(function() {

	$("input[id^='info_id']:visible").autocomplete(Test.supplier);
	
	_change("input[id^='bank_s']:visible", "select[id='bank_t']:visible");

	$("input[id^='name_s']:visible").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: 'contact.php?do=SupplierBank.ajax_zjm',
				dataType: "json",
				data: {
					featureClass: "P",
					style: "full",
					maxRows: 12,
					q: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label: item.name + " [" + item.zjm + ", " + item.bank + "]",
							value: row.name
						}
					}));
				}
			});
		},
		
		minLength: 1
	});
});

var SupplierBank = {

	popup: function (e, p2, id) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var a1 = ['编辑信息', 'url', 'SupplierBank.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
		var a3 = ['复制信息', 'url', 'SupplierBank.dialog_copy_', '650x400'];
		
		var c1 = 'contact.php?do=SupplierBank.edit&id=' + id;
		var c2 = 'contact.php?do=SupplierBank.view&id=' + id;
		var c3 = 'contact.php?do=SupplierBank.copy&id=' + id;

		var s = c1 + ", " + c2 + ", " + c3;

		popup(e, [a1, a2, a3], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.info_id = form.info_id.value;
				
				body.category = form.category.value;
				body.bank = form.bank.value;
				body.branch = form.branch.value;
				body.bankcode = form.bankcode.value;
				
				body.province = form.province.value;
				body.city = form.city.value;
				
				body.zone = form.zone.value;
				body.type = form.type.value;
				
				body.swift = form.swift.value;
				body.name = form.name.value;
				body.code = form.code.value;
				
				body.content = form.content.value;
				body.status = form.status.value;
	
				$(this).dialog("close");
	
				var url = 'contact.php?do=SupplierBank.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.info_id = form.info_id.value;
				
				body.bank = form.bank.value;
				body.branch = form.branch.value;
				body.bankcode = form.bankcode.value;
	
				body.province = form.province.value;
				body.city = form.city.value;
				
				body.zone = form.zone.value;
				body.type = form.type.value;
				
				body.name = form.name.value;
				body.code = form.code.value;
				
				body.content = form.content.value;
	
				$(this).dialog("close");
				
				$.post('contact.php?do=SupplierBank.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	}
};
